package com.zjdiepu.www.rest.api.other;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.annotation.Add;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.enums.status.CreditConfigStatus;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.commpent.handler.TokenUserHelper;
import com.zjdiepu.www.ibiz.other.IOtherInterfaceCreditConfigService;
import com.zjdiepu.www.ibiz.system.IBaseSalersmanService;
import com.zjdiepu.www.model.base.request.CheckInterfaceCreditRequest;
import com.zjdiepu.www.model.other.dto.OtherInterfaceCreditConfig;
import com.zjdiepu.www.util.ExceptionHelper;

/**
 * 接口查询征信配置<br/>
 * @author xiongxiaotun<br/>
 * @time 2018年01月09日 11时24分<br/>
 * @since 1.0<br/>
 */
@RestController
@RequestMapping(value = "OtherInterfaceCreditConfigController", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
@Api(tags = { "接口查询征信配置" }, produces = "application/json;charset=UTF-8")
public class OtherInterfaceCreditConfigController extends BaseController {
    @Resource
    private IOtherInterfaceCreditConfigService otherInterfaceCreditConfigService;
    @Resource
    private IBaseSalersmanService baseSalersmanService;
    @Resource
    private TokenUserHelper tokenUserHelper;
    
    /**
     * @author xiongxiaotun <br/>
     * @Title: checkInterfaceCredit  <br/>
     * @Description: 检查是否可以接口查询征信 <br/>
     * @param checkInterfaceCreditRequest
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "检查是否可以接口查询征信", response = Boolean.class, httpMethod="POST")
    @ApiImplicitParams({
		@ApiImplicitParam(name = SystemConsts.MOBILE_FLAG, defaultValue = "ios", value = "请求机器标识", required = true, paramType = "header", dataType = "String"),
		@ApiImplicitParam(name = SystemConsts.HEADER_FOR_TOKEN, defaultValue = "Ajesget8XF7zNMpt+MM8cr0wI8S+IO6a9giEKNouXWvOO3wWWyaKjSDTqRUtHlcNbjCg1JaPdjRX6dX/O1oGLgE=", value = "token", required = true, paramType = "header", dataType = "String") })
    @RequestMapping(value = "checkInterfaceCredit", method = RequestMethod.POST)
    public ApiResponse checkInterfaceCredit(@Validated(Add.class) @RequestBody CheckInterfaceCreditRequest checkInterfaceCreditRequest) {
    	tokenUserHelper.getUser();
    	OtherInterfaceCreditConfig otherInterfaceCreditConfig = otherInterfaceCreditConfigService.getOtherInterfaceCreditConfigBySalesmanId(checkInterfaceCreditRequest.getBankCode(), checkInterfaceCreditRequest.getSalersmanId());
    	if(null == otherInterfaceCreditConfig) {
    		ExceptionHelper.thow(ResultFlagType.INTERFACE_CREDIT_NOT_ALLOW);
    	}
		String creditConfigStatus = otherInterfaceCreditConfig.getCreditConfigStatus();
		if(!CreditConfigStatus.KE_CHA_XUN.getCode().equals(creditConfigStatus)) {
			ExceptionHelper.thow(ResultFlagType.INTERFACE_CREDIT_NOT_ALLOW);
		}
        return ApiResponse.success(true);
    }
}
